home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 3 / CD ACTUAL 3.iso / linux / sonido / sfxserve.000 / sfxserve / sfxserver-0.02 / device.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-10  |  3.0 KB  |  80 lines

  1. /*
  2.  * ---------------------------------------------------------------------------
  3.  * sfxserver/device.c
  4.  *
  5.  * Copyright by Terry Evans 1994
  6.  * tevans@cs.utah.edu, tevans@slc.unisys.com
  7.  * ---------------------------------------------------------------------------
  8.  *
  9.  * Redistribution and use in source and binary forms, with or without
  10.  * modification, are permitted provided that the following conditions are
  11.  * met: 1. Redistributions of source code must retain the above copyright
  12.  * notice, this list of conditions and the following disclaimer. 2.
  13.  * Redistributions in binary form must reproduce the above copyright notice,
  14.  * this list of conditions and the following disclaimer in the documentation
  15.  * and/or other materials provided with the distribution.
  16.  *
  17.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
  18.  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20.  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
  21.  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  23.  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  24.  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27.  * SUCH DAMAGE.
  28.  * ---------------------------------------------------------------------------
  29.  */
  30.  
  31. #include <fcntl.h>
  32. #include <stdio.h>
  33. #include <linux/soundcard.h>
  34. #include <unistd.h>
  35.  
  36.  
  37. #include "global.h"
  38. #include "types.h"
  39. #include "error.h"
  40. #include "io.h"
  41. #include "device.h"
  42.  
  43.  
  44. int D_Init(char *device, int *frag_spec, int *frequency, int *stereo, int *frag_size)
  45. {
  46.   int s_fd;
  47.  
  48.   IO_WriteStdout("D_Init: Initializing sound device\n");
  49.  
  50.   /* See if we have access to write to the dsp device */
  51.   if(access(device, W_OK))
  52.     E_ErrnoFatalError("D_Init", "unable to get write access to sound device %s", device);
  53.  
  54.   /* We open it and then close it to check if we have opening permission */
  55.   if((s_fd = open(device, O_WRONLY)) == -1)
  56.     E_ErrnoFatalError("D_Init", "unable to open sound device %s", device);
  57.  
  58.   if(ioctl(s_fd, SNDCTL_DSP_SETFRAGMENT, frag_spec))
  59.     E_ErrnoFatalError("D_Init", "unable to ioctl SNDCTL_DSP_SETFRAGMENT on %s", device);
  60.     
  61.   if(ioctl(s_fd, SNDCTL_DSP_SPEED, frequency))
  62.     E_ErrnoFatalError("D_Init", "unable to ioctl SNDCTL_DSP_SPEED on %s", device);
  63.  
  64.   if(ioctl(s_fd, SNDCTL_DSP_STEREO, stereo))
  65.     E_ErrnoFatalError("D_Init", "unable to ioctl SNDCTL_DSP_STEREO on %s", device);
  66.  
  67.   if(ioctl(s_fd, SNDCTL_DSP_GETBLKSIZE, frag_size))
  68.     E_ErrnoFatalError("D_Init", "unable to ioctl SNDCTL_DSP_GETBLKSIZE on %s", device);
  69.  
  70.   /* Return the file descriptor */
  71.   return(s_fd);
  72. }
  73.  
  74.  
  75. void D_DeInit(int s_fd)
  76. {
  77.   IO_WriteStdout("D_DeInit: DeInitializing sound driver\n");
  78.   close(s_fd);
  79. }
  80.